home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / devel / vbcc-68k-src / machines / amiga68k / libsrc / ixemul / ixstacksize.c < prev    next >
C/C++ Source or Header  |  1999-01-01  |  3KB  |  113 lines

  1. /*
  2. **  ixstacksize.c
  3. **
  4. **  Change the stack size for an already compiled ixemul-program
  5. **
  6. **  Compile:
  7. **  vc vlib:minstart.o ixstacksize.c -sc -sd -lamigas -lvcs -nostdlib
  8. **     -o ixstacksize
  9. **
  10. **  Written by Frank Wille 02-Jan-97
  11. **
  12. */
  13.  
  14.  
  15. #include <exec/libraries.h>
  16. #include <exec/memory.h>
  17. #include <dos/dos.h>
  18. #include <dos/rdargs.h>
  19. #include <clib/exec_protos.h>
  20. #include <clib/dos_protos.h>
  21.  
  22.  
  23. static void setstack(ULONG *,UWORD *,ULONG,char *);
  24.  
  25. struct Library *DOSBase=NULL;
  26. static char *rev_string = "$VER: ixstacksize 1.0 (02.02.97)\r\n";
  27.  
  28.  
  29. int main()
  30. {
  31.   LONG argv[] = { 0,0 };
  32.   struct RDArgs *rda;
  33.   struct FileInfoBlock fib;
  34.   BPTR fh;
  35.   UWORD *buf;
  36.  
  37.   if (!(DOSBase = OpenLibrary("dos.library",37)))
  38.     exit(20);
  39.   if (rda = ReadArgs("NAME/A,STACK/K/N",argv,NULL)) {
  40.     if (fh = Open((STRPTR)argv[0],MODE_OLDFILE)) {
  41.       if (ExamineFH(fh,&fib)) {
  42.         if (buf = (UWORD *)AllocVec((unsigned long)fib.fib_Size,
  43.             MEMF_PUBLIC)) {
  44.           if (Read(fh,buf,fib.fib_Size) >= 0) {
  45.             Close(fh);
  46.             setstack((ULONG *)argv[1],buf,fib.fib_Size,(char *)argv[0]);
  47.           }
  48.           else {
  49.             Close(fh);
  50.             Printf("Read error!\n");
  51.           }
  52.           FreeVec(buf);
  53.         }
  54.         else {
  55.           Close(fh);
  56.           Printf("Out of memory!\n");
  57.         }
  58.       }
  59.       else {
  60.         Close(fh);
  61.         Printf("Can't determine size of %s.\n",(char *)argv[0]);
  62.       }
  63.     }
  64.     else
  65.       Printf("Could not open %s.\n",(char *)argv[0]);
  66.     FreeArgs(rda);
  67.   }
  68.   else
  69.     PrintFault(IoErr(),NULL);
  70.   CloseLibrary(DOSBase);
  71. }
  72.  
  73.  
  74. static void setstack(stacksize,buf,bufsize,filename)
  75. ULONG *stacksize;
  76. UWORD *buf;
  77. ULONG bufsize;
  78. char *filename;
  79. {
  80.   UWORD *p=buf;
  81.   ULONG i;
  82.   BPTR fh;
  83.  
  84.   for (i=0; i<=(bufsize-12); i+=2,p++)
  85.     if (*(ULONG *)p==0x5374436b && *(ULONG *)(p+4)==0x7354634b) {
  86.       i = 0;
  87.       break;
  88.     }
  89.   if (i==0) {
  90.     p += 2;
  91.     if (stacksize) {
  92.       if ((i = (*stacksize + 3) & ~3) < 4096) {
  93.         Printf("Stack size must be at least 4096 bytes.\n");
  94.         i = 4096;
  95.       }
  96.       if (fh = Open((STRPTR)filename,MODE_NEWFILE)) {
  97.         *(ULONG *)p = i;
  98.         if (Write(fh,buf,bufsize) < 0) {
  99.           Printf("*** Write error!!! ***\n");
  100.           Close(fh);
  101.           return;
  102.         }
  103.         Close(fh);
  104.       }
  105.       else
  106.         Printf("Can't open %s for writing!\n",filename);
  107.     }
  108.     Printf("Stack size of %s: %ld bytes.\n",filename,*(long *)p);
  109.   }
  110.   else
  111.     Printf("%s doesn't allow to change its stack size.\n",filename);
  112. }
  113.